package com.yanqu.road.server.cmd.beautyescort;

import com.yanqu.road.entity.rank.cross.CrossUnionWeekRank;
import com.yanqu.road.logic.pb.UnionBasePb;
import com.yanqu.road.pb.beautyescort.BeautyEscortProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.beautyescort.CrossBeautyEscortRankMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.math.BigInteger;

@Cmd(code = Protocol.C_BEAUTY_ESCORT_UNION_RANK_CHANGE, desc = "排行数据变更")
public class CrossBeautyEscortUnionRankChangeCmd extends CrossCommand {

    BeautyEscortProto.CrossUnionWeekRankChangeReqMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = BeautyEscortProto.CrossUnionWeekRankChangeReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        for (BeautyEscortProto.CrossUnionWeekRankTemp rankTemp : reqMsg.getRankList()) {
            CrossUnionWeekRank unionWeekRank = new CrossUnionWeekRank();
            unionWeekRank.setValue(BigInteger.valueOf(Long.valueOf(rankTemp.getValue())));
            unionWeekRank.setUnionUid(rankTemp.getUnionUid());
            unionWeekRank.setUnionBaseInfo(UnionBasePb.parseUnionBaseInfo(rankTemp.getUnionInfo()));
            unionWeekRank.setServerId(serverId);
            unionWeekRank.setWeekId(reqMsg.getWeekId());
            CrossBeautyEscortRankMgr.changeUnionRank(reqMsg.getWeekId(), serverId, unionWeekRank);
        }
    }

    @Override
    public void sendData() {

    }
}
